﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class CreditAccount : Account
{
    private decimal creditLimit;
    public decimal CreditLimit { get => creditLimit; private set => creditLimit = value; }

    public CreditAccount(string id, decimal initBalance, decimal creditLimit)
        : base(id, initBalance)
    {
        this.creditLimit = creditLimit;
        Type = AccountType.Credit;
    }

    public override void Withdraw(decimal amount)
    {
        if (amount > Balance + creditLimit)
            throw new InvalidOperationException("超出信用额度！");
        Balance -= amount;
    }

    public override string ToString()
    {
        return base.ToString() + $"，信用额度：{CreditLimit:C}";
    }
}
